﻿package cn.poco.pepsi.util.xmlpared;

import java.io.InputStream;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParser;

import android.util.Xml;
import cn.poco.pepsi.bean.SimpleRestaurant;

public class SimpleRestaurantXmlparse {
	//private final static String TAG = "CityXmlparse";
	private static ArrayList<SimpleRestaurant> simpleRestaurants = null;
	private static  SimpleRestaurant simpleRestaurantBean = null;
	
	public static ArrayList<SimpleRestaurant> getXml(InputStream inSteam) throws Exception{
		XmlPullParser xmpparse = Xml.newPullParser();   //得到解释器
		xmpparse.setInput(inSteam, "UTF-8");           //设置解释流
		int code = xmpparse.getEventType();            //得到节点信息
		while(code!=XmlPullParser.END_DOCUMENT){
			switch (code) {
			case XmlPullParser.START_DOCUMENT:
				simpleRestaurants = new ArrayList<SimpleRestaurant>();
				break;
			case XmlPullParser.START_TAG:
				if("restaurant".equals(xmpparse.getName())){
					simpleRestaurantBean = new SimpleRestaurant();
				}
				if(simpleRestaurantBean!=null){
					if("res-id".equals(xmpparse.getName())){
						String resid = xmpparse.nextText();
						simpleRestaurantBean.setResid(resid);
					}
					if("title".equals(xmpparse.getName())){
						String title = xmpparse.nextText();
						simpleRestaurantBean.setTitle(title);
					}
				}
				break;
			case XmlPullParser.END_TAG:
				if("restaurant".equals(xmpparse.getName())){
					simpleRestaurants.add(simpleRestaurantBean);
					simpleRestaurantBean = null;
				}
				break;
			}	
			code = xmpparse.next();
		}
		inSteam.close();
		return simpleRestaurants;
	}
}
